package com.sky.item.mapper;

import com.sky.item.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @Options(useGeneratedKeys = true,keyProperty = "id") // 主键返回
    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user,status) " +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

//    /**
//     * 分页查询菜品
//     * @param dishPageQueryDTO
//     * @return
//     */
//    Page<DishVO> selectPage(DishPageQueryDTO dishPageQueryDTO);

    /**
     * getById
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * deleteByIds
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 修改菜品:因为对菜品表的status属性有单独修改的情况，所以使用动态sql
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> selectByCategoryId(Long categoryId);

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @Select("select d.* from dish d left join setmeal_dish sd on d.id=sd.dish_id where sd.setmeal_id = #{id}")
    List<Dish> selectBySetmealId(Long id);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 查询所有在售的菜品
     * @return
     */
    List<Dish> selectAll();

    /**
     * 根据菜名模糊查询
     * @return
     */
    @Select("select * from dish where name like concat('%',#{name},'%')")
    List<Dish> getByName(String name);

    List<DishVO> selectAllVO();
}
